package com.turnengine.client.global.game.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Get Game Instance By Name.
 */
public class GetGameInstanceByName implements IGetGameInstanceByName {

	/** The command id. */
	public static final short COMMAND_ID = 309;

	/** The instance name. */
	private String instanceName;
	/** The version id. */
	private int versionId;

	/**
	 * Creates a new Get Game Instance By Name.
	 */
	public GetGameInstanceByName() {
	}

	/**
	 * Creates a new Get Game Instance By Name.
	 * @param instanceName the instance name
	 * @param versionId the version id
	 */
	public GetGameInstanceByName(String instanceName, int versionId) {
		setInstanceName(instanceName);
		setVersionId(versionId);
	}

	/**
	 * Creates a new Get Game Instance By Name.
	 * @param iGetGameInstanceByName the i get game instance by name
	 */
	public GetGameInstanceByName(IGetGameInstanceByName iGetGameInstanceByName) {
		setInstanceName(iGetGameInstanceByName.getInstanceName());
		setVersionId(iGetGameInstanceByName.getVersionId());
	}

	/**
	 * Returns the instance name.
	 * @return the instance name.
	 */
	public String getInstanceName() {
		return instanceName;
	}

	/**
	 * Returns the version id.
	 * @return the version id.
	 */
	public int getVersionId() {
		return versionId;
	}

	/**
	 * Sets the instance name.
	 * @param instanceName the instance name to set.
	 */
	public void setInstanceName(String instanceName) {
		if (instanceName == null) {
			throw new NullPointerException("instanceName");
		}
		this.instanceName = instanceName;
	}

	/**
	 * Sets the version id.
	 * @param versionId the version id to set.
	 */
	public void setVersionId(int versionId) {
		this.versionId = versionId;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(107, 37);
		hash.append(instanceName);
		hash.append(versionId);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GetGameInstanceByName) {
			GetGameInstanceByName compare = (GetGameInstanceByName) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.instanceName, compare.instanceName);
			equals.append(this.versionId, compare.versionId);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGetGameInstanceByName compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.instanceName, compare.getInstanceName());
		builder.append(this.versionId, compare.getVersionId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		if (instanceName != null) {
			string.append("instanceName", instanceName);
		}
		string.append("versionId", versionId);
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
